import logging
import os
from typing import Optional

from fastapi import APIRouter

from app.models import http_resp

qq = APIRouter()

log = logging.getLogger("uvicorn")

# 后端服务地址
spring_boot_address = os.getenv('spring_boot_address')


@qq.get("/items/{item_id}")
async def read_item(item_id: int):
    if item_id == 0:
        raise Exception(f"Failed to download file from OSS:")
    return {"item_id": item_id}


@qq.post("/resp/demo", summary="响应模型示例", response_model=http_resp.HttpResponse)
async def resp_demo(zero: Optional[str] = None):
    log.info("测试")
    log.info(spring_boot_address)
    if not zero:
        raise Exception(f"Failed to download file from OSS:")
        # return http_resp.response_fail("缺少参数")
    raise Exception(1, "失败111")
    # return http_resp.response_success("成功")
